import pytest

@pytest.fixture()
def file_read():
    print("打开文件句柄")
    fo = open("test.txt", "r", encoding="utf-8")
    yield fo
    print("关闭文件句柄")
    fo.close()

@pytest.fixture()
def file_write():
    print("打开文件句柄")
    fo = open("test.txt", "w", encoding="utf-8")
    return fo
    # yield fo
    # print("关闭文件句柄")
    # fo.close()
def test_file(file_read, file_write):
    #写数据
    w = file_write
    w.write("Hello")
    w.close()

    #读数据
    r = file_read
    str = r.read()
    print(str)